import { Table, Space, Card } from "antd";
import { IconDownload } from "@douyinfe/semi-icons";
import { useModel } from "umi";

import SelectDatabaseVersion from "./SelectDatabaseVersion";

const OrganizationIndustry = () => {
    const { selectedOrganization } = useModel("gateway.info");
    const { setModalTitle, setModalVisible, setModalComponent } = useModel("global.modal");

    const updateDatabaseStructure = async (record) => {
        setModalTitle("请选择数据库版本");
        setModalVisible(true);
        setModalComponent(<SelectDatabaseVersion record={record} />);
    };

    return (
        <Card bordered={true} hoverable title="适用行业" size="small" style={{ marginBottom: 10 }} styles={{ body: { padding: 0 } }}>
            <Table size="small" bordered={false} pagination={false} dataSource={selectedOrganization.industryType || []} rowKey="itUuid">
                <Table.Column title="序号" width={60} align="center" render={(_, r, i) => i + 1} />
                <Table.Column title="行业名称" dataIndex="itName" />
                <Table.Column title="参考数据库" dataIndex="itRedb" />
                <Table.Column title="服务名称" dataIndex="itDbna" align="center" />
                <Table.Column title="领域类型" dataIndex="itType" align="center" />
                <Table.Column
                    title="部署的模型版本"
                    dataIndex={"dbVers"}
                    align="center"
                    render={(_, r, i) => selectedOrganization.databases.find((item) => item.itUuid === r.itUuid)?.dbVers || ""}
                />
                <Table.Column
                    title="操作"
                    align="center"
                    width={60}
                    render={(_, r) => {
                        if (selectedOrganization.databaseUser && selectedOrganization.databasePassword) {
                            return (
                                <Space>
                                    {selectedOrganization.databaseDbName && (
                                        <a title="更新数据库结构" onClick={(e) => updateDatabaseStructure(r)}>
                                            <IconDownload />
                                        </a>
                                    )}
                                </Space>
                            );
                        }
                    }}
                />
            </Table>
        </Card>
    );
};

export default OrganizationIndustry;
